/**
 * lottie容器
 * @param {Json} source
 * @param {Number} endNum
 * @param {Boolean} autoPlay
 * @param {Boolean} loop
 * @param {Object} style
 */
import React, {useEffect, useRef} from 'react';
import LottieView from 'lottie-react-native';

import {isEmpty} from '@/utils/utils';
import {hSize, wSize} from '@/utils/size2px';

const LottieBox = ({
  source,
  endNum = 90,
  autoPlay = false,
  loop = false,
  style = {},
}) => {
  const ref = useRef(null);

  if (isEmpty(source)) {
    console.log('==LottieView==Error=：source不能为空');
    return false;
  }

  useEffect(() => {
    ref?.current?.play(0, endNum);
  }, []);

  return (
    <LottieView
      ref={ref}
      source={source}
      autoPlay={autoPlay}
      loop={loop}
      resizeMode="contain"
      style={{
        height: hSize(50),
        width: wSize(50),
        ...style,
      }}
    />
  );
};

export default LottieBox;
